package com.eg366.nioLearn.simple;

import java.io.FileInputStream;
import java.io.IOException;

public class IoRead {

	public static void main(String[] args) throws IOException {
		test01();
		test02();
	}

	private static void test01() throws IOException {
		FileInputStream fis = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("")
				.getPath()
				+ "/readandshow.txt");
		byte[] b = new byte[1024];
		fis.read(b);
		System.out.println(new String(b));
		fis.close();
	}

	private static void test02() throws IOException {
		FileInputStream fis = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("")
				.getPath()
				+ "/readandshow.txt");
		byte[] b = new byte[1024];
		int i;
		int haveRead = 0;
		while ((i = fis.read()) != -1) {
			b[haveRead++] = (byte) i;
		}
		System.out.println(new String(b));
		fis.close();
	}
}
